<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>文章内容</title>
<meta name="robots" content="All" />

<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="css/normalize.css" type="text/css" />
<link rel="stylesheet" href="css/secondary.css" type="text/css" />
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="js/Kunyi.Respond.min.js" ></script><![endif]-->
<script language="javascript" type="text/javascript"
	src="js/KunyiHTML5.min.js"></script>
<script language="javascript" type="text/javascript"
	src="js/Kunyilibrary.js"></script>
<link rel="stylesheet" href="userRegisterAndLogin/css/oksub.css">
</head>
<body>

	<section class="BaseMark">
		<div class="bread">
			您所在的位置<span><a href="index.jsp">首页</a>><a href="news.jsp">科普文章详情</a></span>
		</div>
		<div class="baseLeft">
			<div class="title title05_19">科普文章详情</div>
			<div class="newsMenu">
				<ul>
					<li class="first active"><a href="news.html" title="科普文章"><em>科普文章详情</em></a></li>
				</ul>
			</div>
		</div>
		<div class="baseRight">
			<div class="title01">科普文章详情</div>
			<div class="article detail" id="articleContent">
				<!-- <h2 id="H2Title">äºèæºæ§ç¼çå»èä½å¨é¢å¯å¨</h2>
            <div id="DIVTool" class="title04">
                <span id="SPANDate">åå¸æ¥æï¼2016-12-29</span>
                <div class="itemBase" id="phoneArticle"></div>
                <div class="itemBase share">                
                <div id="bdshare" class="bdshare_b divType" style="padding:0px; float:none;">åäº«æ­¤ç¯æç« ï¼<em class="shareCount"></em>ï¼</div>
				<script type="text/javascript" id="bdshare_js" data="type=button&amp;uid=6713615" ></script><script type="text/javascript" id="bdshell_js"></script><script type="text/javascript">document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date() / 3600000);</script></div>
            </div>
            <div class="clear"></div>
            <div id="DIVContent" class="DIVContent">
            <p>åå®¹</p>
			</div> -->
			</div>

		</div>
		<div class="clear"></div>
	</section>
	<br>
	<!-- 评论富文本框 -->
	<div class="ok-body" id="reply" style="width: 70%; margin-left: 345px;">
		<textarea id="editor" style="display: none;"></textarea>
		<br />
		<button type="button" class="layui-btn" style=" width:400px;" id="textBtn">评论文章</button>
		<button type="button" class="layui-btn" style=" width:400px;margin-left:550px;margin-top:-56px" id="textBtn1">评论<span id="userName">其他用户</span></button>
	</div>
	
		<div class="BottomHidden" style="margin-left: 345px;clear: both;display:inline-block;margin-bottom:70px;height:auto;width:400px;">
			<h3 style=" font-size: 20px; font-weight: 600;">文章评论</h3>
			<div >
				<ul class="commentlist" id="discuss" style="font-size:18px"></ul>
			</div>
		</div>
	 <footer>
		<div class="DWeibo">
			<a href="javascript:;" class="weibo" title="新浪微博">新浪官方微博</a><a
				href="javascript:;" class="tencent" title="腾讯微博">腾讯官方微博</a>
			<div class="clear"></div>
		</div>
		<div class="urlHidden"></div>
		<div class="websiteInfo">
			<div class="info">
				主办单位：医院标题 &nbsp; &nbsp;综合服务电话：120&nbsp;&nbsp; &nbsp;急救中心电话：120
				&nbsp; 传真：120 &nbsp; 地 址：地址地址地址 &nbsp;<br /> 版权所有：医院标题
			</div>
			<ul>
				<li class="first"><a href="jianjie.html" target="_blank">关于我们</a></li>
				<li><a href="Declaration.html" target="_blank">法律声明</a></li>
				<li><a href="SiteMap.html" target="_blank">网站地图</a></li>
				<li><a href="Article-57.html" target="_blank">联系我们</a></li>
				<li><a href="Complain.html" target="_blank">院长(信访)信箱</a></li>
			</ul>
			<div class="clear"></div>
			<div style="margin-bottom: 20px; width: 500px;">
				<textarea class="layui-textarea" id="LAY_demo2"
					style="display: none"></textarea>
			</div>
			<p>
				&copy;2020-
				<script language="javascript" type="text/javascript">
					document.write(new Date().getFullYear());
				</script>
				. All Rights Reserved. <a
					href="http://www.miitbeian.gov.cn/publish/query/indexFirst.action"
					target="_blank">备案号0000001 </a>
			</p>
			<select id="ddlLinks">
				<option value="0"><span>友情链接</span> HYPERLINK
				</option>
				<option value="http://www.cssmoban.com/">模板之家</option>
			</select>
		</div>
	</footer> 
	<!--js逻辑-->
	<script src="userRegisterAndLogin/lib/layui/layui.js"></script>
	<script type="text/javascript">
		layui.use([ "layedit" ], function() {
			let $ = layui.jquery;
			let layedit = layui.layedit;

			let index = layedit.build("editor");
			//评论文章
			$("#textBtn").click(function() {
				//获取文本框内容
				var content=layedit.getText(index);
				$.ajax({
					async : true,
					url : "../DiscussServlet",
					type : "post",
					dataType : "json",
					data : {
						op : "insertDiscuss",
						content:content,
						articleId:"${param.articleId}",
						userId:"${sessionScope.user.userId}"
					},
					success : function(result) {
						if(result!=""){
							sendAJAX();
							alert("评论成功！");
							layedit.setText("");
						}else {
							alert("评论失败！");
						}
						
					},
					error : function() {
						alert("异步请求失败！");
					}

				});
				
			});
			//回复用户的评论
			$("#textBtn1").click(function() {
				//获取文本框内容
				var content=layedit.getText(index);
				$.ajax({
					async : true,
					url : "../DiscussServlet",
					type : "post",
					dataType : "json",
					data : {
						op : "insertReply",
						content:content,
						articleId:"${param.articleId}",
						userId:"${sessionScope.user.userId}",
						discussId:discussId
					},
					success : function(result) {
						if(result!=""){
							sendAJAX();
							alert("评论成功！");
						}else {
							alert("评论失败！");
						}
						
					},
					error : function() {
						alert("异步请求失败！");
					}

				});
			});
		});
	</script>
	<script language="javascript" type="text/javascript"
		src="js/Kunyi.Common.js"></script>
	<script language="javascript" type="text/javascript"
		src="js/Kunyi.Secondary.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			
			var user ="${sessionScope.user}" ;
			if(user==""){
				location.href="../userRegisterAndLogin/pages/userLogin.jsp?msg=error";
			}
			
			$("#LAY_layedit_1").css("height","60px");
			var seachArticle = "${param.op}";
			var articleTitle = "${param.articleTitle}"
			$.ajax({
				async : true,
				type : "get",
				url : "${pageContext.request.contextPath}/ArticleServlet",
				data : {
					op : seachArticle,
					articleTitle : articleTitle
				},success : function(result) {
					var article = result[0];
					var content = "";
					content += "<h2 id=\"H2Title\">"
							+ article.articleTitle
							+ "</h2>"
							+ "<div id=\"DIVTool\" class=\"title04\">"
							+ "<span id=\"SPANDate\">发布时间:"
							+ article.articleTime
							+ "</span>"
							+ "<div class=\"itemBase\" id=\"phoneArticle\"></div>"
							+ "<div class=\"itemBase share\">"
							+ "<div id=\"bdshare\" class=\"bdshare_b divType\" style=\"padding:0px; float:none;\">分享此文章<em class=\"shareCount\"></em>(0)</div>"
							+ "<script type=\"text/javascript\" id=\"bdshare_js\" data=\"type=button&amp;uid=6713615\" >"
							+ "<\/script>"
							+ "<script type=\"text/javascript\" id=\"bdshell_js\">"
							+ "<\/script>"
							+ "<script type=\"text/javascript\">document.getElementById(\"bdshell_js\").src = \"http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=\" + Math.ceil(new Date() / 3600000);<\/script>"
							+ "</div>"
							+ "</div>"
							+ "<div class=\"clear\"></div>"
							+ "<div id=\"DIVContent\" class=\"DIVContent\">"
							+ "<p>"
							+ article.articleContent
							+ "</p>" + "</div>"
					$("#articleContent").html(content);
				},
				error : function() {
					alert("异步失败！");
				}
			})
		})
	</script>
</body>
<script type="text/javascript">
//获取评论id
var discussId="";
function getDiscussId(object){
	discussId=$(object).data("id");
	var discussName=$(object).data("name");
	$("#userName").text(discussName);
	location.href="#reply";
}
//入口函数
$(function() {
	//页面加载，查询本文章所有评论
	sendAJAX();
});
//查询本文章所有评论
function sendAJAX(){
	$.ajax({
		async : true,
		url : "../DiscussServlet",
		type : "post",
		dataType : "json",
		data : {
			op : "searchDiscuss",
			articleId:"${param.articleId}"
		},
		success : function(result) {
			 $("#discuss").html("")
			show(result)
		},
		error : function() {
			alert("异步请求失败！");
		}

	});
}
//渲染一级评论
	function show(result){
		for ( var i in result) {
			if(result[i].discuss.discussId==0){
				$("#discuss").append("<li  style=\"list-style:none; ;display:block;width:auto;\">"+result[i].user.userName+
						"评论："+result[i].discussContent+
						"<br><span>"+result[i].discussTime+"</span>"+
						"<br><a href=\"#\" onclick=deleteById(this) data-id=\""+result[i].discussId+"\">删除</a>&nbsp;&nbsp;<a onclick=getDiscussId(this) data-id=\""+result[i].discussId+"\" data-name=\""+result[i].user.userName+"\"  href=\"#\">回复</a></li>");
				findDicuss(result[i],result);
			}
		}
	}

	//渲染二级评论
	function findDicuss(result1,result) {
		for ( var j in result) {
		 if (result[j].discuss.discussId==result1.discussId) {
			 $("#discuss").append("<ul style=\"margin-left:30px;;display:block;\"><li >"+result[j].user.userName+
						"评论"+result[j].discuss.user.userName+"："+result[j].discussContent+
						"<br><span>"+result[j].discussTime+"</span>"+
						"<br><a href=\"#\" onclick=deleteById(this) data-id=\""+result[j].discussId+"\">删除</a>&nbsp;&nbsp;<a onclick=getDiscussId(this) data-id=\""+result[j].discussId+"\" data-name=\""+result[j].user.userName+"\" href=\"#reply\">回复</a></li></ul>");
			 if (result1.discussId!=0) {
				 findDicuss(result[j],result);
			}
		}
	}
}
	
	//删除评论	
	function deleteById(object){
		$.ajax({
			async : true,
			url : "../DiscussServlet",
			type : "post",
			dataType : "json",
			data : {
				op : "deleteDiscuss",
				discussId:$(object).data("id"),
				userId:"${sessionScope.user.userId}"
			},
			success : function(result) {
				if(result!=""){
				sendAJAX();
				alert("删除成功！")
				}
					
				
			},
			error : function() {
				alert("删除失败！您不能删除别人的评论！")
			}

		});
	}
	
   
</script>
</html>
